package com.bubble.base.common.exception;

import org.apache.commons.lang3.exception.ExceptionUtils;


/**
 * 业务异常基类
 * 所有业务异常都必须继承于此异常
 * @author yhaoquan
 *
 */
public class BizException extends AppException {

	private static final long serialVersionUID = 1L;
	
	/**
	 * 业务异常
	 */
	public static final BizException BIZ_ERROR = new BizException("业务异常") ;

	/**
	 * 异常描述信息
	 */
	private String msg ;
	
	public BizException() {}

	public BizException(String msgFormat, Object...args) {
		super(String.format(msgFormat, args));
		this.msg = String.format(msgFormat, args);
	}
	
	public BizException logError() {
		this.logger.error(this.msg);
		return new BizException(this.msg) ;
	}
	
	public BizException logError(Exception e) {
		return errorMsg(e) ;
	}
	
	public BizException errorMsg(Exception e) {
		this.logger.error(this.msg + "\r\n" + ExceptionUtils.getMessage(e));
		return new BizException(this.msg + " - " + ExceptionUtils.getRootCauseMessage(e)) ;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

}
